package cn.support.neo.mvp.core.di.module;

import android.accounts.AccountManager;
import android.content.Context;

import com.github.pwittchen.prefser.library.Prefser;

import javax.inject.Singleton;

import cn.support.neo.mvp.App;
import cn.support.neo.mvp.core.di.qualifier.ForApplication;
import cn.support.neo.mvp.core.provider.GuestTokenProvider;
import cn.support.neo.mvp.core.service.client.HttpClient;
import cn.support.neo.mvp.core.service.client.RetrofitClient;
import dagger.Module;
import dagger.Provides;
import eu.unicate.retroauth.AuthAccountManager;

@Module
public class AppModule {

    private final App app;

    public AppModule(App app) {
        this.app = app;
    }

    @Provides
    @Singleton
    @ForApplication
    Context provideAppContext() {
        return app;
    }

    @Provides
    @Singleton
    Prefser providePrefser(@ForApplication Context context) {
        return new Prefser(context);
    }

    @Provides
    @Singleton
    GuestTokenProvider provideGuestTokenProvider(Prefser prefser) {
        return new GuestTokenProvider(prefser);
    }

    @Provides
    @Singleton
    HttpClient provideHttpClient(@ForApplication Context context, Prefser prefser) {
        return new RetrofitClient(context, prefser);
    }

    @Provides
    @Singleton
    AccountManager provideAccountManager(@ForApplication Context context) {
        return AccountManager.get(context);
    }

    @Provides
    @Singleton
    AuthAccountManager provideAuthAccountManager(@ForApplication Context context, AccountManager accountManager) {
        return new AuthAccountManager(context, accountManager);
    }
}